<template>
  <div class="u-p-10 date-record">
    <div class="header">
      <div class="left">
        <div class="top">
          <div class="title">{{ titleText }}</div>
          <div class="picker-time">
            <!-- <el-select v-model="activeMonth" placeholder="月份" @change="onChange">
                            <el-option
                                v-for="item in options"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            ></el-option>
                        </el-select> -->
            <el-date-picker
              v-model="value2"
              type="month"
              placeholder="月份"
              value-format="yyyy-MM"
              @change="onChange"
            >
            </el-date-picker>
             <div class="time-btn" @click="onMore">更多</div>
          </div>
        </div>
        <div class="day-box">
          <div
            class="day"
            :class="{ 'active-day': day.has == 1 }"
            v-for="(day, index) in dayData"
            :key="index"
            @click="onDayClick(day.day)"
          >
            <div class="day-text">
              {{ day.day }}
              <span class="dot"></span>
            </div>
          </div>
        </div>
      </div>
      <div class="right">
        <div class="btn" @click="onAdd">{{ addBtnText }}</div>
        <slot name="morebtn"></slot>
      </div>
    </div>
  </div>
</template>

<script>
import { formatTime } from "@/libs/util.js";
export default {
  name: "dateRecord",
  props: {
    titleText: String,
    addBtnText: {
      type: String,
      default: "新增记录",
    },
    dayData: {},
  },
  data() {
    return {
      value2: "",
      activeYear: "",
      activeMonth: "",
      totalDay: 28,
      options: [
        { label: "一月", value: 1 },
        { label: "二月", value: 2 },
        { label: "三月", value: 3 },
        { label: "四月", value: 4 },
        { label: "五月", value: 5 },
        { label: "六月", value: 6 },
        { label: "七月", value: 7 },
        { label: "八月", value: 8 },
        { label: "久月", value: 9 },
        { label: "十月", value: 10 },
        { label: "十一月", value: 11 },
        { label: "十二月", value: 12 },
      ],
    };
  },
  computed: {},
  methods: {
    curMonth() {
      let date = formatTime(new Date(), true);
      this.activeYear = date.y;
      this.activeMonth = date.m;
      this.value2 = date.y + "-" + date.m;
      this.totalDay = new Date(date.y, this.activeMonth, 0).getDate();
    },
    onChange(e) {
      let time = e.split("-");
      let year = time[0];
      let month = time[1];
      this.activeYear = year;
      this.activeMonth = month;
      this.totalDay = new Date(year, month, 0).getDate();
      this.$emit("onChange", e);
    },
    onMore() {
      this.$emit("onMore", {});
    },
    onAdd() {
      this.$emit("onAdd");
    },
    onDayClick(day) {
      day = day < 10 ? "0" + day : day;
      this.$emit("onDay", this.activeYear + "-" + this.activeMonth + "-" + day);
    },
  },
  mounted() {},
  created() {
    this.curMonth();
  },
  watch: {
   
  },
};
</script>

<style lang="scss" scoped>
.picker-time{
    display: flex;
}
.time-btn{
    margin-left: 20px;
    padding-top: 10px;
}
.date-record {
  background-color: #fff;
  .header {
    display: flex;
    justify-content: space-between;
    .left {
      margin-right: 50px;
      .top {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        margin-bottom: 20px;
      }
      .title {
        margin-right: 10px;
        font-weight: 600;
      }
    }
    .right {
      flex-shrink: 0;
      .btn {
        font-size: 12px;
        border-radius: 10px;
        cursor: pointer;
        padding: 5px 15px;
        color: #fff;
        background-color: #73baff;
        display: inline-block;
      }
    }
  }
  .day-box {
    display: flex;
    flex-wrap: wrap;
    .day {
      width: 40px;
      height: 25px;
      text-align: center;
      line-height: 25px;
      font-size: 14px;
      &.active-day {
        .day-text {
          cursor: pointer;
        }
        .dot {
          background-color: #04c017;
        }
      }
      .day-text {
        display: inline-block;
        position: relative;
        padding: 0 2px;
      }
      .dot {
        position: absolute;
        top: 0;
        right: -6px;
        width: 10px;
        height: 10px;
        border-radius: 50%;
        background-color: transparent;
      }
    }
  }
}
</style>
